//
//  HCMainViewController.swift
//  Hweibome
//
//  Created by 何川 on 15/12/5.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit
import SVProgressHUD

class HCMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = HCTabBar()
        tabBar.composeButtonClosure = {
            [weak self] in
           // printLog("撰写按钮点击了")
            if !HCUserAccountViewModel.sharedAccount.userLogon {
                SVProgressHUD.showErrorWithStatus("请先登录")
                return
            }
            //printLog(self?.view)
            let composeView = HCComposeView()
//            let window = UIApplication.sharedApplication().windows.last
//            window?.addSubview(composeView)
            composeView.show(self)
        }
        setValue(tabBar, forKeyPath: "tabBar")
        addChildViewController(HCHomeViewController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(HCMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(HCDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(HCProfileViewController(), imgName: "tabbar_profile", title: "我")
        
        //self.performSelector("dismiss",withObject: nil , afterDelay: 5)
        
    }

    func dismiss()
    {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func addChildViewController(childController: UIViewController , imgName:String ,title:String ) {
        //
        childController.tabBarItem = HCTabBarItem()
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imgName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        addChildViewController(HCNavigationController(rootViewController:childController))
        
    }

    deinit{
        printLog("main 销毁")
    }

 

}
